package com.person.leetcode.editor.cn;

import java.util.ArrayList;

/**
  * 6.N 字形变换
  * 2023-02-14 22:10:36
**/
public class Sequence_0006_ZigzagConversion {
    public static void main(String[] args) {
        Solution solution = new Sequence_0006_ZigzagConversion().new Solution();
    }
    //leetcode submit region begin(Prohibit modification and deletion)
class Solution {
    public String convert(String s, int numRows) {
        if(numRows < 2) return s;
        ArrayList<StringBuilder> arr = new ArrayList<>();
        for (int i = 0; i < numRows; i++) {
            arr.add(new StringBuilder());
        }
        int row = 0;
        int flag = -1;
        for (char c : s.toCharArray()) {
            arr.get(row).append(c);
            if (row == 0 || row == numRows - 1) flag = -flag;
            row += flag;
        }
        StringBuilder res = new StringBuilder();
        for (StringBuilder str : arr) {
            res.append(str);
        }
        return res.toString();
    }
}
//leetcode submit region end(Prohibit modification and deletion)

}